package com.study.english.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.study.english.context.SecurityContextHolder;
import com.study.english.domain.SysVideo;
import com.study.english.pojo.vo.SysVideoTypeVo;
import com.study.english.result.Result;
import com.study.english.service.ISysVideoService;
import com.study.english.service.ISysVideoTypeService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

import com.study.english.domain.SysVideoType;

import org.springframework.web.bind.annotation.*;

/**
 * 学习视频类型
 *
 * @author wf
 * @description 针对表【sys_video_type(学习视频类型)】的数据库操作Controller
 * @createDate 2024-03-11 15:56:35
 */
@RestController
@RequestMapping("sysVideoType")
public class SysVideoTypeController {

    @Autowired
    private ISysVideoTypeService sysVideoTypeService;
    @Autowired
    private ISysVideoService sysVideoService;


    /**
     * 新增:学习视频类型
     */
    @PostMapping("addSysVideoType")
    public Result addSysVideoType(@RequestBody SysVideoTypeVo sysVideoTypeVo) {
        sysVideoTypeService.addSysVideoType(sysVideoTypeVo);
        return Result.success();

    }


    /**
     * 分页查询:学习视频类型
     */
    @PostMapping("getSysVideoTypePageList")
    public Result getSysVideoTypePageList(@RequestBody SysVideoTypeVo sysVideoTypeVo) {
        IPage<SysVideoTypeVo> page = new Page<>(sysVideoTypeVo.getPageNum(), sysVideoTypeVo.getPageSize());
        sysVideoTypeVo.setUserId(SecurityContextHolder.getUserId());
        IPage<SysVideoTypeVo> list = sysVideoTypeService.getSysVideoTypePageList(page, sysVideoTypeVo);
        return Result.success(list);
    }


    /**
     * 不分页查询:学习视频类型
     */

    @PostMapping("getSysVideoTypeList")
    public Result getSysVideoTypeList(@RequestBody SysVideoTypeVo sysVideoTypeVo) {
        List<SysVideoTypeVo> sysVideoTypeVoList = sysVideoTypeService.getSysVideoTypeList(sysVideoTypeVo);

        return Result.success(sysVideoTypeVoList);
    }

    /**
     * 根据id查询详情:学习视频类型
     */

    @GetMapping("getSysVideoTypeById")
    public Result getSysVideoTypeById(@RequestParam String id) {
        SysVideoType sysVideoType = sysVideoTypeService.getSysVideoTypeById(id);
        return Result.success(sysVideoType);
    }

    /**
     * 根据id删除:学习视频类型
     */
    @GetMapping("delSysVideoType")
    public Result delSysVideoType(@RequestParam(value = "id") String id) {
        List<SysVideo> videoTypeList = sysVideoService.list(new QueryWrapper<SysVideo>().eq("video_type_id", id));
        if (videoTypeList != null && videoTypeList.size() != 0) {
            return Result.failed("不能删除！视频详情还存在！");
        }
        sysVideoTypeService.delSysVideoType(id);

        return Result.success();
    }


    /**
     * 修改:学习视频类型
     */
    @PostMapping("updateSysVideoType")
    public Result updateSysVideoType(@RequestBody SysVideoTypeVo sysVideoTypeVo) {
        sysVideoTypeService.updateSysVideoType(sysVideoTypeVo);
        return Result.success();

    }
}
